home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4617 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1022 b 

  1. Path: news.cc.uic.edu!usenet
  2. From: Qi Zeng <zeng@sunphy1.phy.uic.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: variable length string
  5. Date: 6 Feb 1996 04:43:45 GMT
  6. Organization: University of Illinois at Chicago
  7. Message-ID: <4f6ma1$613e@tigger.cc.uic.edu>
  8. References: <4f5s97$8sho@tigger.cc.uic.edu> <9602052314.AA18664@dxmint.cern.ch>
  9. NNTP-Posting-Host: sunphy1.phy.uic.edu
  10.  
  11. Dan Pop <danpop@mail.cern.ch> wrote:
  12. >
  13. > Qi Zeng <zeng@sunphy1.phy.uic.edu> writes:
  14. > >  >Suppose you want to read from stdin a string, but you do not know how 
  15. > >long it will be. You have to assign the string to some char*,  
  16. > Use fgets with a reasonably sized buffer.  After reading the string,
  17. > use strlen to find out its real length, malloc the right amount of memory 
  18. > and copy the string there (dropping the terminating '\n').
  19. > > Dan
  20.  
  21. Thanks.
  22.  
  23. And yes, it is a way to do that. But how to deal with the space you 
  24.  
  25. malloced? Say you return a char *, which points to the space you jsut 
  26.  
  27. malloced. When do you free them? 
  28.  
  29. Qi Zeng 
  30.    
  31.  
  32.